programming4us
           
 
 
SQL Server

SQL Server : Changing What Is Already Stored

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
10/24/2010 4:38:35 PM
You alter data through the use of UPDATE. Just as with the input of data, any alterations made to the data are subject to the rules and constraints defined in the table schema. Any data modifications made that do not meet these defined standards result in errors that the front-end application may have to trap and control.

Updating a Single Record

There are three different techniques for updating a single record:

  • Filtered update— This technique is no different than changing a number of records. The difference is that the criteria used need to be something unique, such as a primary key or an identity.

  • Positioned update— This technique is a programmatic solution. Essentially, you set up a procedure that scrolls through the data. When the record pointer (that is, cursor) is on the record to be updated, you issue the UPDATE command with the WHERE CURRENT OF clause.

  • Computed column— You can update a single record by using a computed column. In this case, when the computation involves a field whose value changes, the result of the computation is affected and the field will change.

Doing Updates That Affect Multiple Records

Most data modifications are based on a conditional operation or are in-place updates of the current record. The following is a basic UPDATE statement that adjusts data based on the criteria given:

UPDATE Customers
SET Region = 'South America'
WHERE Country IN ('Argentina', 'Brazil', 'Venezuela')

Obviously, an update performed with a broad condition will affect a number of records. Records in other tables could be affected. In the event of cascading updates, if a referenced row has its key altered, those changes would ripple down to the related rows of the subsidiary table.

Performing Transaction Processing

Updating data within a transaction gives you a chance to undo changes before they are actually saved to the database. This usually comes into play when there are a number of steps needed for the data alteration to be valid. If any of the steps within the process fails, you can roll back everything that has been done, which leaves the system as if no change had ever occurred.

The key to handling transactions is to know when to commit the change and when to roll it back. You usually execute the ROLLBACK statement as part of a conditional operation that checks for lack of success in the process. If an error occurs in a transaction, you roll back the transaction. If the user decides to cancel the transaction, you roll back the transaction. If a portion of a required process cannot be completed, you roll back the transaction.

A ROLLBACK statement backs out all modifications made in the transaction. This statement returns the data to the state it was in at the start of the transaction. When errors occur, you should use COMMIT or ROLLBACK. You use COMMIT if you want to ensure that changes are saved to the point of the error, and you use ROLLBACK to cancel all changes.

One effective tool for handling errors, including those in transactions, is the new T-SQL TRY/CATCH construct, illustrated here:

BEGIN TRY
-- Attempt the desired processing
COMMIT
END TRY
BEGIN CATCH
-- An error occurred, handle it or
ROLLBACK
END CATCH;
GO

Normally, ROLLBACK would occur during the CATCH operation; however, if desired, a COMMIT could be coded there as well to save the changes instead of abandoning the operation.

Upgrading Data from Previous Releases of SQL Server

If you have worked with SQL Server for a while and are comfortable with the four-part naming convention for addressing objects, you will be comfortable working with the new object schemas, which also uses a four-part name for addressing objects:

Server.Catalog.Schema.Object

The Schema portion historically was addressed as the object owner. All objects on previous instances of the server were generally owned by dbo. That makes the most common schema for upgraded databases the dbo schema. For comparison purposes, you can visit the Microsoft website, at www.microsoft.com/sql/downloads/2005/default.mspx, and install the sample databases Pubs, Northwind, and AdventureWorks and compare the object naming conventions.

Other -----------------
- Using System Tables and Views
- SQL Server 2005 : Data Querying Using Full-Text Indexes
- SQL Dependency Reporting
- The Overall Disaster Recovery Process
- Microsoft SQL Server Options for Disaster Recovery
- How to Approach Disaster Recovery
- SQL Server 2008 : Database Mirroring
- Creating and Using a SQL Azure Database
- SQL Server 2008 : Failover Clustering
- SQL Server 2008 Reporting Services : Management and Security
- SQL Server 2008: Security and User Administration - Authentication Methods
- SQL Server 2008: Security and User Administration - Managing Principals (part 2) - Roles
- SQL Server 2008: Security and User Administration - Managing Principals (part 1) - Users
- SQL Server 2008: Security and User Administration - Managing Securables
- SQL Server 2008: Security and User Administration - Managing Permissions
- SQL Server 2008: Security and User Administration - Managing SQL Server Logins
- Managing SQL Server Permissions (part 4) - Using T-SQL to Manage Permissions
- Managing SQL Server Permissions (part 2) - Using SSMS to Manage Permissions at the Object Level
- Managing SQL Server Permissions (part 2) - Using SSMS to Manage Permissions at the Database Level
- Managing SQL Server Permissions (part 1) - Using SSMS to Manage Permissions at the Server Level
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us